package zhoug.demo.zui.ui;

import android.os.Bundle;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Switch;
import android.widget.TextView;

import java.text.MessageFormat;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import zhoug.demo.zui.R;
import zhoug.zui.dialog.date.ZUIMultiDateChooser;

/**
 * @Author: zhoug
 * @Date: 2024-07-18
 * @Description:
 */
public class ZUIMultiDateChooserActivity extends AppCompatActivity {
    private int mOrientation= ZUIMultiDateChooser.HORIZONTAL;
    private RadioButton radioDate;
    private RadioButton radioTime;
    private RadioGroup radioGroup;
    private Switch switchVertical;
    private Button btnDate;
    private Button btnTime;
    private Button btnDateTime;
    private TextView tvTime;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_multi_date_chooser);
        findViews();
        onCreated(savedInstanceState);
    }

   
    protected void onCreated(@Nullable Bundle savedInstanceState) {
        switchVertical.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mOrientation=isChecked?ZUIMultiDateChooser.VERTICAL:ZUIMultiDateChooser.HORIZONTAL;
            }
        });

        btnDate.setOnClickListener(v -> {
            ZUIMultiDateChooser dateChooser = new ZUIMultiDateChooser(this);
            dateChooser.setDateMode(ZUIMultiDateChooser.MODE_DATE);
            dateChooser.setCallback(new ZUIMultiDateChooser.Callback() {
                @Override
                public void onSelectDate(String startTime, String endTime) {
                    tvTime.setText(MessageFormat.format("{0} 至 {1}", startTime, endTime));
                }
            });
            dateChooser.show();
        });

        btnTime.setOnClickListener(v -> {
            ZUIMultiDateChooser dateChooser = new ZUIMultiDateChooser(this);
            dateChooser.setDateMode(ZUIMultiDateChooser.MODE_TIME);
            dateChooser.setCallback(new ZUIMultiDateChooser.Callback() {
                @Override
                public void onSelectDate(String startTime, String endTime) {
                    tvTime.setText(MessageFormat.format("{0} 至 {1}", startTime, endTime));
                }
            });
            dateChooser.show();
        });
        btnDateTime.setOnClickListener(v -> {
            ZUIMultiDateChooser dateChooser = new ZUIMultiDateChooser(this);
            dateChooser.setDateMode(ZUIMultiDateChooser.MODE_DATE_TIME);
            dateChooser.setOrientation(mOrientation);
            dateChooser.setCallback(new ZUIMultiDateChooser.Callback() {
                @Override
                public void onSelectDate(String startTime, String endTime) {
                    tvTime.setText(MessageFormat.format("{0} 至 {1}", startTime, endTime));
                }
            });
            dateChooser.show();
        });

    }


    private void findViews() {
        radioDate = findViewById(R.id.radio_date);
        radioTime = findViewById(R.id.radio_time);
        radioGroup = findViewById(R.id.radioGroup);
        switchVertical = findViewById(R.id.switch_vertical);
        btnDate = findViewById(R.id.btn_date);
        btnTime = findViewById(R.id.btn_time);
        btnDateTime = findViewById(R.id.btn_dateTime);
        tvTime = findViewById(R.id.tv_time);
    }
}
